﻿using AutoMapper;
using MediatR;
using RedDragon.Common.Domain.AuthorizeRBAC;
using RedDragon.Common.Dtos;
using RedDragon.Common.Infrastructure.Interface;
using RedDragon.RBAC.API.Application.Common.Resourec;
using RedDragon.RBAC.ErrorCodeEnum;
using SqlSugar;
using T.Common.Domain.Common;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
namespace RedDragon.RBAC.API.Application.Common.Client
{
    public class QueryClientHandler : IRequestHandler<QueryClientComand, Result>
    {
        /// <summary>
        /// mapper
        /// </summary>
        private readonly IMapper mapper;
        /// <summary>
        /// 客户仓储
        /// </summary>
        public readonly IBaseRepository<Clients> clientsRepository;


        public QueryClientHandler(IMapper mapper, IBaseRepository<Clients> clientsRepository)
        {
            this.mapper = mapper;
            this.clientsRepository = clientsRepository;
        }
        /// <summary>
        /// 客户列表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>

        public async Task<Result> Handle(QueryClientComand request, CancellationToken cancellationToken)
        {
            var result = new Result();
            var list = await (await clientsRepository.GetAll()).Where(x=>x.IsDel==0).ToArrayAsync();
            result.Data = list;
            return result;
        }
    }
}
